# -*- coding:utf-8 -*-
from django.db import models
from django.contrib.auth.models import User


class Topic(models.Model):
    """
        用户学习的主题
    """
    text = models.CharField(max_length=200)
    date_added = models.DateTimeField(auto_now_add=True)

    owner = models.ForeignKey(User, models.CASCADE)

    class Meta:
        ordering = ['-date_added']
        verbose_name = '主题'
        verbose_name_plural = verbose_name


    def __str__(self):
        return self.text


class Entry(models.Model):
    """
        学到的有关某个主题的具体知识。
    """
    topic = models.ForeignKey(Topic, on_delete=models.CASCADE)
    text = models.TextField()
    date_added = models.DateTimeField(auto_now_add=True)

    class Meta:
        verbose_name = "实体"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.text[:50] + '...'
